package com.jinmdz.fmis.dao.admin.dao;

import com.jinmdz.fmis.dao.admin.dao.provider.ServiceDictionaryProvider;
import com.jinmdz.fmis.dao.admin.model.servicedictionary.ServiceDictionaryDataEditItem;
import com.jinmdz.fmis.dao.admin.model.servicedictionary.ServiceDictionaryDataListItem;
import com.jinmdz.fmis.dao.admin.model.servicedictionary.ServiceDictionaryDataRuleItem;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;

import java.util.ArrayList;

/**
 * 字典费用关联及计算规则设置Dao
 *
 * @author GuanKui
 * @date 2020/3/12 11:36
 */
public interface ServiceDictionaryDao {

    /**
     * 根据dict_code获取字典费用关联及计算规则信息
     *
     * @param dictCode 查询字典编码
     * @return
     * @author GuanKui
     * @date 2020/3/9  15:35
     */
    @SelectProvider(type = ServiceDictionaryProvider.class, method = "listServiceDictionaryDataListByDictCode")
    ArrayList<ServiceDictionaryDataListItem> listServiceDictionaryDataListByDictCode(@Param("dictCode") String dictCode);

    /**
     * 根据服务字典关联主键及字典主键获取字典费用关联及计算规则信息
     *
     * @param id               service_dictionary_item表ID
     * @param dataDictionaryId data_dictionary表查询ID
     * @return
     * @author GuanKui
     * @date 2020/3/9  15:35
     */
    @SelectProvider(type = ServiceDictionaryProvider.class, method = "getServiceDictionaryDataEditByDictionaryId")
    ServiceDictionaryDataEditItem getServiceDictionaryDataEditByDictionaryId(@Param("id") Integer id, @Param("dataDictionaryId") Integer dataDictionaryId);

    /**
     * 按照主键获取关联信息
     *
     * @param id 主键
     * @return
     * @author LiCongLu
     * @date 2020-03-28 15:14
     */
    @SelectProvider(type = ServiceDictionaryProvider.class, method = "getServiceDictionaryDataEditById")
    ServiceDictionaryDataEditItem getServiceDictionaryDataEditById(@Param("id") Integer id);

    /**
     * 获取计算规则
     *
     * @param initialCode 业务类型规则编码开头
     * @return
     * @author GuanKui
     * @date 2020/3/12  17:23
     */
    @SelectProvider(type = ServiceDictionaryProvider.class, method = "listServiceDictionaryDataRuleForCode")
    ArrayList<ServiceDictionaryDataRuleItem> listServiceDictionaryDataRuleForCode(@Param("initialCode") String initialCode);

    /**
     * 根据用途、物品id，字典id获取字典费用关联及计算规则信息
     *
     * @param serviceDictionaryId 主键
     * @param dataDictionaryId    data_dictionary表查询ID
     * @param purpose             用途
     * @return
     * @author GuanKui
     * @date 2020/3/12  16:26
     */
    @Select(" select id from service_dictionary_item where id != IFNULL(#{serviceDictionaryId},0) and data_dictionary_id = #{dataDictionaryId} " +
            " and purpose = #{purpose}  and deleted = 0 limit 1 ")
    Integer getServiceDictionaryItemIdByPurpose(@Param("serviceDictionaryId") Integer serviceDictionaryId, @Param("dataDictionaryId") Integer dataDictionaryId, @Param("purpose") String purpose);
}
